package tech.wetech.admin.web.controller.system;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import tech.wetech.admin.common.base.Result;
import tech.wetech.admin.service.system.BillService;
import tech.wetech.admin.service.system.OrganizationService;
import tech.wetech.admin.service.system.RoleService;
import tech.wetech.admin.web.controller.base.BaseController;
import tech.wetech.admin.web.dto.system.BillData;

import java.util.ArrayList;
import java.util.List;

@Controller
@RequestMapping("/billdata")
public class BillDataController extends BaseController {
    @Autowired
    private BillService billService;
    @Autowired
    private OrganizationService organizationService;

    @Autowired
    private RoleService roleService;
    @RequestMapping(method = RequestMethod.GET)
    @RequiresPermissions("billdata:view")
    public String toPage(Model model) {
        setCommonData(model);
        return "system/billdata";
    }

    @ResponseBody
    @RequestMapping(value = "/getExpense", method = RequestMethod.POST)
    @RequiresPermissions("billdata:view")
    public Result GetExpenseInfo(String year){
        List<BillData> exbdlist =new ArrayList<BillData>();
        exbdlist = billService.findExpenseInfo(year);
        return Result.Success(exbdlist);
    }

    @ResponseBody
    @RequestMapping(value = "/getIncome", method = RequestMethod.POST)
    @RequiresPermissions("billdata:view")
    public Result GetIncomeInfo(String year){
        List<BillData> inbdlist =new ArrayList<BillData>();
        inbdlist = billService.findIncomeInfo(year);
        return Result.Success(inbdlist);
    }

    private void setCommonData(Model model) {
        model.addAttribute("organizationList", organizationService.findAll());
        model.addAttribute("roleList", roleService.findAll());
    }
}
